﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using MINERP.DAL;
using MINERP.MODEL.FoundationModel;
using MINERP.MODEL.PrintManage;

namespace MINERP.BLL.PrintManage
{
    public class PaperWasteRecord
    {
        public int Insert(PaperWasteRecordModel paperWasteRecordInfo, out int PaperWasteRecordId)
        {
            int ret = 0;
            PaperWasteRecordId = 0;
            using (newSampleYPDBEntities entities = new newSampleYPDBEntities())
            {
                try
                {
                    PaperWasteRecords pWasteRecord = new PaperWasteRecords();
                    pWasteRecord.CreateTime = paperWasteRecordInfo.CreateTime;
                    pWasteRecord.Length = paperWasteRecordInfo.Length;
                    pWasteRecord.PaperInfo = entities.PaperInfo.FirstOrDefault(p => p.PrintPaperId == paperWasteRecordInfo.PaperInfo.PrintPaperId);
                    pWasteRecord.PaperWasteType = entities.PaperWasteType.FirstOrDefault(p => p.Id == paperWasteRecordInfo.PaperWasteType.Id);
                    pWasteRecord.Remark = paperWasteRecordInfo.Remark;
                    pWasteRecord.Status = paperWasteRecordInfo.Status;
                    pWasteRecord.Width = paperWasteRecordInfo.Width;
                    pWasteRecord.PrinterWaste = paperWasteRecordInfo.PrinterWaste;
                    entities.AddToPaperWasteRecords(pWasteRecord);
                    entities.SaveChanges();

                    PaperWasteRecordId = pWasteRecord.Id;
                }
                catch
                {
                    ret = -1;
                }
            }
            return ret;
        }
    }
}
